/**
 * Created by XiongXuan on 2018/1/11.
 */
var updateUserInfoUrl = "http://127.0.0.1:8085/adminASDF/query-person";
var deleteUserUrl = "http://127.0.0.1:8085/adminASDF/query-person";
var deleteProjectUrl = "http://127.0.0.1:8085/adminASDF/query-project";
var updateProjectUrl = "http://127.0.0.1:8085/adminASDF/query-project";
var userPendingUrl = "http://127.0.0.1:8085/adminASDF/check-person";
var projectPendingUrl = "http://127.0.0.1:8085/adminASDF/check-project";
var logoutUrl = "http://127.0.0.1:8085/adminASDF";

function logout() {
    $.ajax({
        traditional: true,
        type: "DELETE", //用POST方式传输
        url: logoutUrl,
        // data: {"phoneNumber":phoneNumber,
        //     "nickName":nickName,
        //     "userType":userType,
        //     "schoolName":schoolName,
        //     "major":major,
        //     "contactType": contactType,
        //     "contact": contact,
        //     "intro": intro
        // },
        success: function (result) {
            console.log(result);
            if (result.code == 1) {
                // alert(result.msg);
                location.reload();
            }
            else {
                alert(result.msg);
            }
        },
        datatype: "json"
    });
}

function modifyInfo() {
    var nickName = encodeURI(document.getElementById("nickName").value);
    var phoneNumber = document.getElementById("phoneNumber").value;
    var userType  = $('input[name="userType"]:checked').val();
    var schoolName = encodeURI(document.getElementById("schoolName").value);
    var major = encodeURI(document.getElementById("major").value);
    var contactType = document.getElementById("contactType").value;
    var contact = document.getElementById("contact").value;
    var intro = encodeURI(document.getElementById("intro").value);

    $.ajax({
        traditional: true,
        type: "POST", //用POST方式传输
        url: updateUserInfoUrl,
        data: {"phoneNumber":phoneNumber,
            "nickName":nickName,
            "userType":userType,
            "schoolName":schoolName,
            "major":major,
            "contactType": contactType,
            "contact": contact,
            "intro": intro
        },
        success: function (result) {
            console.log(result);
            if (result.code == 1) {
                alert(result.msg);
                location.reload();
            }
            else {
                alert(result.msg);
            }
        },
        datatype: "json"
    });
}

function deleteUser(phoneNumber) {
    $.ajax({
        traditional: true,
        type: "DELETE", //用POST方式传输
        url: deleteUserUrl + "?phoneNumber=" + phoneNumber,
        // data: {"phoneNumber":phoneNumber
        // },
        success: function (result) {
            console.log(result);
            if (result.code == 1) {
                alert(result.msg);
                location.reload();
            }
            else {
                alert(result.msg);
            }
        },
        datatype: "json"
    });
}

function deleteProject(projectId) {
    $.ajax({
        traditional: true,
        type: "DELETE", //用POST方式传输
        url: deleteProjectUrl + "?projectId=" + projectId,
        // data: {"phoneNumber":phoneNumber
        // },
        success: function (result) {
            console.log(result);
            if (result.code == 1) {
                alert(result.msg);
                location.reload();
            }
            else {
                alert(result.msg);
            }
        },
        datatype: "json"
    });
}

function updateProject() {
    var projectId = document.getElementById("projectId").value;
    var phoneNumber = document.getElementById("owner").value;
    var name = document.getElementById("name").value;
    var type = document.getElementById("type").value;
    var contactType = document.getElementById("contactType").value;
    var contact = document.getElementById("contact").value;
    var field = document.getElementById("field").value;
    var intro = document.getElementById("intro").value;

    $.ajax({
        traditional: true,
        type: "POST", //用POST方式传输
        url: updateProjectUrl,
        data: {
            "id": projectId,
            "phoneNumber": phoneNumber,
            "name":name,
            "type":type,
            "contactType":contactType,
            "contact": contact,
            "field": field,
            "intro": intro
        },
        success: function (result) {
            console.log(result);
            if (result.code == 1) {
                alert(result.msg);
                location.reload();
            }
            else {
                alert(result.msg);
            }
        },
        datatype: "json"
    });
}

function passUserPending(pendingId, phoneNumber, changedUserType) {
    var adminId = document.getElementById("adminId").innerText;
    var result = 1;
    $.ajax({
        traditional: true,
        type: "POST", //用POST方式传输
        url: userPendingUrl,
        data: {
            "changedUserType":changedUserType,
            "phoneNumber": phoneNumber,
            "adminId":adminId,
            "result":result,
            "id":pendingId
        },
        success: function (result) {
            console.log(result);
            if (result.code == 1) {
                alert(result.msg);
                location.reload();
            }
            else {
                alert(result.msg);
            }
        },
        datatype: "json"
    });
}

function failUserPending(pendingId, phoneNumber, changedUserType) {
    var adminId = document.getElementById("adminId").innerText;
    var result = 0;
    $.ajax({
        traditional: true,
        type: "POST", //用POST方式传输
        url: userPendingUrl,
        data: {
            "changedUserType":changedUserType,
            "phoneNumber": phoneNumber,
            "adminId":adminId,
            "result":result,
            "id":pendingId
        },
        success: function (result) {
            console.log(result);
            if (result.code == 1) {
                alert(result.msg);
                location.reload();
            }
            else {
                alert(result.msg);
            }
        },
        datatype: "json"
    });
}

function passProjectPending(pendingId, projectId) {
    var adminId = document.getElementById("adminId").innerText;
    var result = 1;
    $.ajax({
        traditional: true,
        type: "POST", //用POST方式传输
        url: projectPendingUrl,
        data: {
            "pendingProjectId": projectId,
            "adminId":adminId,
            "result":result,
            "id":pendingId
        },
        success: function (result) {
            console.log(result);
            if (result.code == 1) {
                alert(result.msg);
                location.reload();
            }
            else {
                alert(result.msg);
            }
        },
        datatype: "json"
    });
}

function failProjectPending(pendingId, projectId) {
    var adminId = document.getElementById("adminId").innerText;
    var result = 0;
    $.ajax({
        traditional: true,
        type: "POST", //用POST方式传输
        url: projectPendingUrl,
        data: {
            "pendingProjectId": projectId,
            "adminId":adminId,
            "result":result,
            "id":pendingId
        },
        success: function (result) {
            console.log(result);
            if (result.code == 1) {
                alert(result.msg);
                location.reload();
            }
            else {
                alert(result.msg);
            }
        },
        datatype: "json"
    });
}